﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace EzDesk.Apps.Model.Attendance
{
    /// <summary>
    /// 描述某一天的假期状况
    /// </summary>
    [DataContract]
    public class DayLeaveInfo
    {
        public DayLeaveInfo()
            :this(DateTime.Now)
        {
        }

        public DayLeaveInfo(DateTime date, bool isWholeDay = false)
        {
            Date = date;
            IsWholeDay = isWholeDay;

            this.Leaves = new List<DayLeaveInfoItem>();
        }

        /// <summary>
        /// 全天放假
        /// </summary>
        [DataMember]
        public bool IsWholeDay { get; set; }

        [DataMember]
        public DateTime Date { get; private set; }

        /// <summary>
        /// 一天中所有的请假条目
        /// </summary>
        [DataMember]
        public List<DayLeaveInfoItem> Leaves { get; set; }

        private bool hasLeave
        {
            get
            {
                return Leaves != null && Leaves.Count > 0;
            }
        }

        public bool HasLeave
        {
            get
            {
                return hasLeave;
            }
        }

        public DayLeaveInfoItem FirstLeave
        {
            get
            {
                if (hasLeave)
                {
                    return Leaves.First();
                }
                return null;
            }
        }

        
    }
}
